Pinpoint Coffee Bean shops on the map
Cafes are very common in Korea, and many of them are franchise business. In this excercise I will visualize one of the franchise, Coffee Bean, with around 240 shops on the map.
import pandas as pd
import folium
from folium.features import GeoJson,GeoJsonTooltip
import warnings
warnings.filterwarnings("ignore")
#load the dataset with Coffee Bean shop addresses
df = pd.read_csv('address_243_R.csv')
df = df.iloc[:,0:4]
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 243 entries, 0 to 242 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Store 243 non-null object 1 Address 243 non-null object 2 Latitude 243 non-null float64 3 Longitude 243 non-null float64 dtypes: float64(2), object(2) memory usage: 7.7+ KB
df.head(2)
| Store | Address | Latitude | Longitude | |
|---|---|---|---|---|
| 0 | 학동역 DT점 | 서울특별시 강남구 학동로 211 1층 | 37.514818 | 127.032057 |
| 1 | 수서점 | 서울특별시 강남구 광평로 280 수서동 724호 | 37.487496 | 127.103044 |
#create the base map
korea_map = folium.Map(location=[37.561051861516475, 126.98643859619223],zoom_start=10)
lat_n_long = list(set(zip(list(df['Latitude']),list(df['Longitude']),list(df['Store']),list(df['Address']))))
for i,v,s,a in lat_n_long:
marker = folium.Marker(location=[i,v],tooltip=('<b>커피빈'+'<p><b> Store: '+s + '<p><b> Address: '+a))
marker.add_to(korea_map)
#hover to show the cafe name and address
korea_map
Add district line on the map
To have a better idea of cafe distribution in different districts, I will add the district line.
import json
import os
#load the Korea district geojson file
geo_path = os.path.join(os.getcwd(), 'KOR_adm2-2.json')
geo = json.load(open(geo_path, encoding='utf-8'))
#examine the contents in the json file
geo.keys()
dict_keys(['type', 'features'])
geo['features'][0]
{'type': 'Feature',
'geometry': {'type': 'Polygon',
'coordinates': [[[128.9957275390626, 35.17683410644537],
[129.0012664794923, 35.173828125000114],
[129.00732421875023, 35.17226409912115],
[129.01431274414062, 35.170513153076286],
[129.02224731445324, 35.17083358764654],
[129.0326843261721, 35.17560577392578],
[129.041015625, 35.17989730834961],
[129.0480194091798, 35.18355941772461],
[129.05506896972668, 35.189632415771484],
[129.06005859375, 35.19593048095709],
[129.0665283203125, 35.203716278076286],
[129.07015991210938, 35.21379852294922],
[129.0611267089845, 35.218902587890625],
[129.0625000000001, 35.226501464843864],
[129.0662841796876, 35.2313232421875],
[129.06927490234375, 35.23730468750006],
[129.0665283203125, 35.24548339843756],
[129.06292724609375, 35.25427246093756],
[129.06549072265648, 35.26171875000006],
[129.0697021484376, 35.266906738281364],
[129.07611083984375, 35.27429199218756],
[129.08250427246105, 35.28470993041998],
[129.07330322265625, 35.28048706054699],
[129.0570983886721, 35.27780151367199],
[129.04870605468773, 35.27410888671881],
[129.04290771484375, 35.269287109375],
[129.0354003906251, 35.26101684570324],
[129.02972412109375, 35.25427246093756],
[129.023681640625, 35.24908447265625],
[129.02288818359375, 35.24029541015625],
[129.01809692382812, 35.23129272460932],
[129.01251220703136, 35.221313476562614],
[129.009521484375, 35.21527099609369],
[129.0054931640625, 35.2103271484375],
[129.00030517578136, 35.20672607421875],
[128.998291015625, 35.19250488281256],
[128.9957275390626, 35.17683410644537]]]},
'properties': {'ID_0': 213,
'ISO': 'KOR',
'NAME_0': 'South Korea',
'ID_1': 1,
'NAME_1': 'Busan',
'ID_2': 1,
'NAME_2': 'Buk',
'HASC_2': '',
'CCN_2': 0,
'CCA_2': '',
'TYPE_2': 'Gu',
'ENGTYPE_2': 'District',
'NL_NAME_2': '북구| 北區',
'VARNAME_2': ''}}
#Ouline the district and insert district name
district = folium.GeoJson(
geo,
style_function=lambda x:{'fillColor':'lightyellow','fillOpacity':0.2},
popup=folium.GeoJsonPopup(fields=['NL_NAME_2'],aliases=['District: '])
).add_to(korea_map)
folium.LayerControl().add_to(korea_map)
<folium.map.LayerControl at 0x1fb7516ee10>
#click to show the district name
korea_map